package com.mall.web.control.eshop;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONArray;
import com.mall.biz.ImageUploadBizImpl;
import com.mall.biz.eshop.EshopBizImpl;
import com.mall.biz.mallRecommend.MallRecommendBizImpl;
import com.mall.biz.user.VerifyCodeBizImpl;
import com.mall.biz.user.record.CollectionBizImpl;
import com.mall.client.eshop.EshopBannerService;
import com.mall.client.eshop.EshopCompanyService;
import com.mall.client.eshop.EshopService;
import com.mall.client.eshop.EshopTouchService;
import com.mall.client.eshop.EshopTrademarkService;
import com.mall.client.eshop.EshopUserInfoService;
import com.mall.client.eshop.SaleEshopService;
import com.mall.client.search.EShopLuceneBuildService;
import com.mall.client.user.UserExtendedService;
import com.mall.common.util.PageUtil;
import com.mall.common.util.bit.PropertiesConfigure;
import com.mall.constant.PropertiesKey;
import com.mall.constant.ReqAttributeKey;
import com.mall.constant.UserConstant;
import com.mall.enums.CollectionEnum;
import com.mall.enums.EshopErrorTypeEnum;
import com.mall.enums.EshopUserInfoEnum;
import com.mall.enums.MallRecommendEnum;
import com.mall.enums.SaleEshopStatusEnum;
import com.mall.enums.SaleEshopTypeEnum;
import com.mall.pojo.Collection;
import com.mall.pojo.Eshop;
import com.mall.pojo.EshopBanner;
import com.mall.pojo.EshopCompany;
import com.mall.pojo.EshopTouch;
import com.mall.pojo.EshopTouchExample;
import com.mall.pojo.EshopTrademark;
import com.mall.pojo.EshopUserInfo;
import com.mall.pojo.MallRecommend;
import com.mall.pojo.SaleEshop;
import com.mall.pojo.User;
import com.mall.pojo.UserExtended;
import com.mall.query.Page;
import com.mall.query.eshop.EshopUserQuery;
import com.mall.query.eshop.SaleEshopQuery;
import com.mall.vo.eshop.CollectionVO;
import com.mall.vo.eshop.SaleEshopQO;
import com.mall.vo.eshop.SaleEshopVO;
import com.mall.web.annotation.AdminSecurity;
import com.mall.web.annotation.EShopUserSecurity;
import com.mall.web.annotation.UserSecurity;
import com.mall.web.util.CookieUtil;
import com.mall.web.util.HttpUtil;
import com.mall.web.util.Log4jUtil;
import com.mall.web.util.MaiGeDianWebUtil;
import com.mall.web.util.MoneyUtil;
import com.mall.web.util.PinYinUtil;
import com.mall.web.util.StringUtil;
import com.mall.web.util.WebUtil;
import com.mall.web.vo.ResponseEntity;

@Controller
@RequestMapping("/eshop/")
/**
 * 首页，列表页等
 * @author Administrator
 *
 */
public class EshopController {

	@Autowired
	private EshopUserInfoService eshopUserInfoService;
	@Autowired
	private EshopService eshopService;
	@Autowired
	private SaleEshopService saleEshopService;
	@Autowired
	private EshopCompanyService eshopCompanyService;
	@Autowired
	private EshopTrademarkService eshopTrademarkService;
	@Autowired
	private EShopLuceneBuildService eShopLuceneBuildService;
	@Autowired
	private CollectionBizImpl collectionBizImpl;
	@Autowired
	private ImageUploadBizImpl imageUploadBizImpl;
	@Autowired
	private PropertiesConfigure propertiesConfigure;
	@Autowired
	private UserExtendedService userExtendedService;
	@Autowired
	private MallRecommendBizImpl mallRecommendBizImpl;
	@Autowired
	private EshopTouchService eshopTouchService;
	@Autowired
	private EshopBizImpl eshopBizImpl;
	// 图片保存的文件夹名字
	private final String folder = "eshop";
	@Autowired
	private EshopBannerService eshopBannerService;
	@Autowired
	private VerifyCodeBizImpl verifyCodeBizImpl;

	/**
	 * 买个店pc端首页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcindex")
	public String pcindex(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		pcindexModelMap(request, response, modelMap);
		return "eshop/pcindex";
	}

	/**
	 * pc端忘记密码
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcForgetPassword")
	public String pcForgetPassword(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/pcForgetPassword";
	}

	public ModelMap pcindexModelMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		User user = WebUtil.getCurrentUser(request);

		List<MallRecommend> mallRecommendList = this.mallRecommendBizImpl
				.getEshopMallRecomendList(MallRecommendEnum.TIANMAOESHOPRECOMMEND.getCode(), onlyKey);
		List<SaleEshop> saleEshopList = this.eshopBizImpl.getSaleEshopListByRecommend(mallRecommendList);
		List<SaleEshopVO> saleEshopVOList = this.eshopBizImpl.getSaleEshopVOListBySaleEshopList(saleEshopList);
		List<EshopBanner> eshopBannerList = this.eshopBannerService.getEshopBannerListByPageAndStatus(null, 1, 0);
		Integer count = this.eshopBannerService.getEshopBannerCountByStatusAndType(1, 0);
		
		Page page = new Page();
		page.setPageByPageNoAndPageSize(1, 5);
		
		List<EshopBanner> eshopBannerListxin = this.eshopBannerService.getEshopBannerListByPageAndStatus(page, 1, 1);
		List<EshopBanner> eshopBannerListQuestion = this.eshopBannerService.getEshopBannerListByPageAndStatus(page, 1, 2);
		List<EshopBanner> eshopBannerListInterview = this.eshopBannerService.getEshopBannerListByPageAndStatus(page, 1, 3);
		

		modelMap.put("eshopBannerListxin", eshopBannerListxin);
		modelMap.put("eshopBannerListQuestion", eshopBannerListQuestion);
		modelMap.put("eshopBannerListInterview", eshopBannerListInterview);

		modelMap.put("bannerSize", count + 1);
		modelMap.put("eshopBannerList", eshopBannerList);
		modelMap.put("saleEshopVOList", saleEshopVOList);
		modelMap.put("user", user);
		return modelMap;
	}

	/**
	 * 买个店pc端店铺列表页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	// @UserLoginMessage
	@RequestMapping("pcEshopList")
	public String pcEshopList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		pcEshopListModelMap(request, response, modelMap);
		return "eshop/pcEshopList";
	}

	/**
	 * pc列表页分页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcEshopMoreList")
	public String pcEshopMoreList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		pcEshopListModelMap(request, response, modelMap);
		return "eshop/include/pcindexEshopInclude";
	}

	public ModelMap pcEshopListModelMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		User user = WebUtil.getCurrentUser(request);

		// 设置分页
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE_ESHOPLIST);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);

		String keyWord = request.getParameter("keyWord");
		if (StringUtil.isNotBlank(keyWord)) {
			try {
				keyWord = URLDecoder.decode(URLDecoder.decode(keyWord, "UTF-8"), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}

		Integer qualification = HttpUtil.getIntegerValueFromRequest(request, "qualification");
		Integer taxpayer = HttpUtil.getIntegerValueFromRequest(request, "taxpayer");
		Integer trademark = HttpUtil.getIntegerValueFromRequest(request, "trademark");
		Integer price = HttpUtil.getIntegerValueFromRequest(request, "price");
		Integer industry = HttpUtil.getIntegerValueFromRequest(request, "industry");
		String orderBy = HttpUtil.getStringValueFromRequest(request, "orderBy");

		SaleEshopQuery saleEshopQuery = new SaleEshopQuery();
		saleEshopQuery.setOnlyKey(onlyKey);
		saleEshopQuery.setKeyWord(keyWord);
		saleEshopQuery.setOrderby(orderBy);
		saleEshopQuery.setQualification(qualification);
		saleEshopQuery.setTaxpayer(taxpayer);
		saleEshopQuery.setTrademark(trademark);
		saleEshopQuery.setPrice(price);
		saleEshopQuery.setIndustry(industry);
		saleEshopQuery.setStatus(0);
		int size = this.saleEshopService.getSaleEshopCountByQuery(saleEshopQuery);
		saleEshopQuery.setPage(page);
		List<SaleEshop> saleEshopList = this.saleEshopService.getSaleEshopListBySaleEshopQuery(saleEshopQuery);
		List<SaleEshopVO> saleEshopVOList = this.eshopBizImpl.getSaleEshopVOListBySaleEshopList(saleEshopList);

		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE_ESHOPLIST);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("industry", industry);
		modelMap.put("trademark", trademark);
		modelMap.put("taxpayer", taxpayer);
		modelMap.put("price", price);
		modelMap.put("user", user);
		modelMap.put("qualification", qualification);
		modelMap.put("saleEshopVOList", saleEshopVOList);
		modelMap.put("keyWord", keyWord);
		modelMap.put("orderBy", orderBy);
		return modelMap;
	}

	/**
	 * pc端登录
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcEshopLogin")
	public String pcEshopLogin(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcEshopLogin";
	}

	/**
	 * pc端注册
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcEshopRegister")
	public String pcEshopRegister(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcEshopRegister";
	}

	/**
	 * pc端店铺详情页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcEshopDetail")
	public String pcEshopDetail(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		eshopDetail(request, response, modelMap);
		return "eshop/pcEshopDetail";
	}

	/**
	 * h5出售店铺展示列表
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("saleEshopList")
	public String saleEshopList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		CookieUtil.setCookie(response, ReqAttributeKey.COOKIE_FOR_COMMKEYID, "2");
		saleEshopListMap(request, response, modelMap);
		return "eshop/saleEshopList";
	}

	/**
	 * h5出售店铺展示列表加载更多
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("saleEshopListMore")
	public String saleEshopListMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		CookieUtil.setCookie(response, ReqAttributeKey.COOKIE_FOR_COMMKEYID, "2");
		saleEshopListMap(request, response, modelMap);
		return "eshop/include/saleEshopListMore";
	}

	public ModelMap saleEshopListMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		String keyWord = HttpUtil.getStringValueFromRequest(request, "keyWord");
		Integer pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		Integer pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE_APP);
		modelMap.put("keyWord", keyWord);
		Page page = new Page();
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		// 得到目前正在出售中的天貓店铺信息
		SaleEshopQuery saleEshopQuery = new SaleEshopQuery();
		saleEshopQuery.setStatus(0);
		saleEshopQuery.setKeyWord(keyWord);
		saleEshopQuery.setOnlyKey(onlyKey);
		saleEshopQuery.setStatus(SaleEshopStatusEnum.ZAISHOU.getSaleEshopStatus());
		saleEshopQuery.setType(SaleEshopTypeEnum.TIANMAO.getSaleEshopType());
		saleEshopQuery.setPage(page);
		List<SaleEshop> saleTianmaoEshopList = this.saleEshopService.getSaleEshopListBySaleEshopQuery(saleEshopQuery);

		List<EshopBanner> eshopBannerList = this.eshopBannerService.getEshopBannerListByPageAndStatus(null, 1, 0);
		modelMap.put("eshopBannerList", eshopBannerList);
		modelMap.put("saleTianmaoEshopList", saleTianmaoEshopList);
		return modelMap;
	}

	/**
	 * h5评估
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pinggusignup")
	public String pinggusignup(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/pinggusignup";
	}

	/**
	 * h5评估提交
	 * 
	 * @param eshopUserInfo
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pinggusignupaction")
	public String pinggusignupaction(EshopUserInfo eshopUserInfo, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		String leimu = request.getParameter("leimu");
		String nianyingyee = request.getParameter("nianyingyee");
		String monthyingyee = request.getParameter("monthyingyee");

		Map<String, String> map = new HashMap<>();
		map.put("leimu", leimu);
		map.put("nianyingyee", nianyingyee);
		map.put("monthyingyee", monthyingyee);
		JSONArray jsonArray = new JSONArray();
		jsonArray.add(map);
		eshopUserInfo.setType(EshopUserInfoEnum.PINGGU.getCode());
		eshopUserInfo.setAttribute(StringUtils.isBlank(eshopUserInfo.getAttribute()) ? jsonArray.toJSONString()
				: eshopUserInfo.getAttribute().toString() + jsonArray.toJSONString());
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setStatus(EshopUserInfoEnum.WEILIANXI.getCode());
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));
		this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone,
				"用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交店铺评估信息");
		return "eshop/pcindex";
	}

	/**
	 * h5待入驻
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("dairuzhusignup")
	public String dairuzhusignup(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/dairuzhusignup";
	}

	/**
	 * h5待入住提交
	 * 
	 * @param eshopUserInfo
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("dairuzhusignupsignupaction")
	public String dairuzhusignupsignupaction(EshopUserInfo eshopUserInfo, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		String dairuzhuleimu = request.getParameter("dairuzhuleimu");
		Map<String, String> map = new HashMap<>();
		map.put("dairuzhuleimu", dairuzhuleimu);
		JSONArray jsonArray = new JSONArray();
		jsonArray.add(map);
		eshopUserInfo.setType(EshopUserInfoEnum.DAIRUZHU.getCode());
		eshopUserInfo.setAttribute(StringUtils.isBlank(eshopUserInfo.getAttribute()) ? jsonArray.toJSONString()
				: eshopUserInfo.getAttribute().toString() + jsonArray.toJSONString());
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setStatus(EshopUserInfoEnum.WEILIANXI.getCode());
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));
		this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone,
				"用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交了代入驻信息");
		return "eshop/signupsucc";
	}

	/**
	 * pc待入住信息提交action'
	 * 
	 * @param eshopUserInfo
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcsignupsignupaction")
	@ResponseBody
	public ResponseEntity<EshopUserInfo> pcsignupsignupaction(EshopUserInfo eshopUserInfo, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		String dairuzhuleimu = request.getParameter("dairuzhuleimu");
		if (StringUtils.isNotBlank(dairuzhuleimu)) {
			Map<String, String> map = new HashMap<>();
			map.put("dairuzhuleimu", dairuzhuleimu);
			JSONArray jsonArray = new JSONArray();
			jsonArray.add(map);
			eshopUserInfo.setAttribute(StringUtils.isBlank(eshopUserInfo.getAttribute()) ? jsonArray.toJSONString()
					: eshopUserInfo.getAttribute() + jsonArray.toJSONString());
		}
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setStatus(0);
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));
		this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		ResponseEntity<EshopUserInfo> responseEntity = new ResponseEntity<>();
		responseEntity.initSuccResponseEntity(eshopUserInfo, "succ");
		if (!responseEntity.getCode().equals("200")) {
			Log4jUtil.printLog(EshopErrorTypeEnum.SELLERERROR.getDesc(), eshopUserInfo.getPhone());
		}
		String content = "";
		if (eshopUserInfo.getType() == 0) {
			content = "用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交了卖店信息";
		} else if (eshopUserInfo.getType() == 1) {
			content = "用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交了买店信息";
		}
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone, content);
		return responseEntity;

	}

	/**
	 * pc端首页转代入住
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcDairuzhu")
	public String pcDairuzhu(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcDairuzhu";
	}

	// h5待入驻跳转
	@RequestMapping("dairuzhu")
	public String dairuzhu(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/dairuzhu";
	}

	/**
	 * pc端待入住展示页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcdairuzhusignup")
	public String pcdairuzhusignup(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcdairuzhusignup";
	}

	/**
	 * pc端网店评估
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcPinggu")
	public String pcPinggu(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcPinggu";
	}

	@RequestMapping("pcPingguAction")
	public String pcPingguAction(EshopUserInfo eshopUserInfo, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		String leimu = request.getParameter("leimu");
		String nianyingyee = request.getParameter("nianyingyee");
		String monthyingyee = request.getParameter("monthyingyee");
		String baozhengjin = request.getParameter("baozhengjin");

		Map<String, String> map = new HashMap<>();
		map.put("leimu", leimu);
		map.put("nianyingyee", nianyingyee);
		map.put("monthyingyee", monthyingyee);
		map.put("baozhengjin", baozhengjin);
		JSONArray jsonArray = new JSONArray();
		jsonArray.add(map);
		eshopUserInfo.setType(EshopUserInfoEnum.PINGGU.getCode());
		eshopUserInfo.setAttribute(StringUtils.isBlank(eshopUserInfo.getAttribute()) ? jsonArray.toJSONString()
				: eshopUserInfo.getAttribute().toString() + jsonArray.toJSONString());
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setStatus(EshopUserInfoEnum.WEILIANXI.getCode());
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));
		Integer result = this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		if (result == null || result <= 0) {
			Log4jUtil.printLog(EshopErrorTypeEnum.ASSESSMENTERROR.getDesc(), eshopUserInfo.getPhone());
		}
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone,
				"用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交了网店评估信息");
		return "eshop/signupsucc";
	}

	/**
	 * h5卖店登录
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("selleshopsignup")
	public String selleshopsignup(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/selleshopsignup";
	}

	/**
	 * h5卖店信息提交
	 * 
	 * @param eshopUserInfo
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("eshopsignupaction")
	public String eshopsignupaction(EshopUserInfo eshopUserInfo, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		String laiyuan = request.getParameter("laiyuan");
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setStatus(0);
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));
		Integer result = this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		if (result == null || result <= 0) {
			Log4jUtil.printLog(EshopErrorTypeEnum.SELLERERROR.getDesc(), eshopUserInfo.getPhone());
		}
		String content = "";
		if (eshopUserInfo.getType() == 0) {
			content = "用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交了卖店信息";
		} else if (eshopUserInfo.getType() == 1) {
			content = "用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交了买店信息";
		}
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone, content);
		if (StringUtils.isNotBlank(laiyuan) && "pc".equalsIgnoreCase(laiyuan)) {
			return "eshop/pcsignupsucc";
		}
		return "eshop/signupsucc";
	}

	/**
	 * 买店登录
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("buyeshopsignup")
	public String buyeshopsignup(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/buyeshopsignup";
	}

	@RequestMapping("pcselleshopsignup")
	public String pcselleshopsignup(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcselleshopsignup";
	}

	@RequestMapping("pcbuyeshopsignup")
	public String pcbuyeshopsignup(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcbuyeshopsignup";
	}

	/**
	 * 后台首页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backoperate")
	@UserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backeshopinfoIndex(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/backoperate";
	}

	/**
	 * 后台列表页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backeshopinfoList")
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backeshopinfoList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		backeshopinfoListModelMap(request, response, modelMap);
		return "eshop/backeshopinfoList";
	}

	/**
	 * 后台列表加载更多
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backeshopinfoListMore")
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backeshopinfoListMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		backeshopinfoListModelMap(request, response, modelMap);
		return "eshop/include/backeshopinfoListMore";
	}

	public ModelMap backeshopinfoListModelMap(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		// 0:卖家 1:买家 0:卖家 9:评估 8:代入驻 7:个人需求
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE_APP);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);

		Integer type = HttpUtil.getIntegerValueFromRequest(request, "type");
		if (type == null) {
			return null;
		}
		EshopUserQuery eshopUserQuery = new EshopUserQuery();
		eshopUserQuery.setType(type);
		eshopUserQuery.setPage(page);
		List<EshopUserInfo> eshopUserInfoList = eshopBizImpl.getEshopUserInfoListByQuery(eshopUserQuery);
		modelMap.put("eshopUserInfoList", eshopUserInfoList);
		User user = WebUtil.getCurrentUser(request);
		modelMap.put("user", user);
		modelMap.put("type", type);
		return modelMap;
	}

	/**
	 * 后台修改联系、未联系
	 */
	@RequestMapping("changeBackInfoStatus")
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<Boolean> changeBackInfoStatus(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(userId);
		eshopUserInfo.setStatus(1);
		if (this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo) == 1) {
			responseEntity.setCode("200");
			responseEntity.setData(null);
			responseEntity.setMessage("修改成功");
		}
		return responseEntity;
	}

	/**
	 * 后台收藏列表页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backCollectionList")
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backCollectionList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		backCollectionModelMap(request, response, modelMap);
		return "eshop/backCollectionList";
	}

	/**
	 * 后台收藏列表页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backCollectionListMore")
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backCollectionListMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		backCollectionModelMap(request, response, modelMap);
		return "eshop/include/backCollectionListMore";
	}

	public ModelMap backCollectionModelMap(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		Page page = new Page();
		Integer pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		Integer pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE_APP);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);

		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		List<Collection> eshopCollectionList = this.collectionBizImpl.getCollectionByUserIdAndOnlyKey(null, onlyKey,
				null, page, CollectionEnum.ESHOPTYPE.getCode(), CollectionEnum.COLLECTION.getCode());
		List<CollectionVO> collectionVOList = this.collectionBizImpl
				.getCollectionVOListByCollectionList(eshopCollectionList);
		modelMap.put("collectionVOList", collectionVOList);
		return modelMap;
	}

	/**
	 * h5后台修改备注
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backeshopinfomodify")
	@ResponseBody
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<Boolean> backeshopinfomodify(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Long eshopUserInfoId = HttpUtil.getLongValueFromRequest(request, "eshopUserInfoId");
		if (eshopUserInfoId == null || eshopUserInfoId <= 0) {
			responseEntity.initErrorResponseEntity(false, "eshopUserInfoId error");
			return responseEntity;
		}
		EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(eshopUserInfoId);
		String remarks = request.getParameter("remarks");// 备注
		eshopUserInfo.setRemark(remarks);
		this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo);
		responseEntity.initSuccResponseEntity(true, "succ");
		return responseEntity;
	}

	/**
	 * h5个人中心提交留言
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("addPersonalCenterRemark")
	@EShopUserSecurity
	public ResponseEntity<Boolean> addPersonalCenterRemark(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		User currentUser = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		EshopUserInfo eshopUserInfo = new EshopUserInfo();

		String remark = HttpUtil.getStringValueFromRequest(request, "remark");
		eshopUserInfo.setType(EshopUserInfoEnum.LIIUYAN.getCode());
		eshopUserInfo.setCommOnlyKey(onlyKey);
		eshopUserInfo.setName(currentUser.getUserName());
		eshopUserInfo.setPhone(currentUser.getPhone());
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setUserId(currentUser.getId());
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));
		if (StringUtils.isNotBlank(remark)) {
			eshopUserInfo.setRemark(remark);
		}
		int num = this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		if (num == 0) {
			responseEntity.initErrorResponseEntity(false, "error");
			Log4jUtil.printLog(EshopErrorTypeEnum.LIUYANERROR.getDesc(), currentUser.getPhone());
			return responseEntity;
		}
		responseEntity.initSuccResponseEntity(true, "success");
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone,
				"用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "在个人中心提交了留言");
		return responseEntity;

	}

	@RequestMapping("saleEshopAction")
	public String SaleEshopAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {

		String name = HttpUtil.getStringValueFromRequest(request, "name");
		String phone = HttpUtil.getStringValueFromRequest(request, "phone");
		Long qq = HttpUtil.getLongValueFromRequest(request, "qq");
		String wangwang = HttpUtil.getStringValueFromRequest(request, "wangwang");
		String eshopUrl = HttpUtil.getStringValueFromRequest(request, "eshopUrl");
		Integer type = HttpUtil.getIntegerValueFromRequest(request, "type");

		EshopUserInfo eshopUserInfo = new EshopUserInfo();
		eshopUserInfo.setEshopUrl(eshopUrl);
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setName(name);
		eshopUserInfo.setPhone(phone);
		eshopUserInfo.setWangwang(wangwang);
		eshopUserInfo.setType(type);
		eshopUserInfo.setQq(qq);
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));

		Integer relust = this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		if (relust == null || relust <= 0) {
			Log4jUtil.printLog(EshopErrorTypeEnum.SELLERERROR.getDesc(), phone);
		}
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone,
				"用户：" + eshopUserInfo.getName() + "  手机：" + eshopUserInfo.getPhone() + "提交了卖店信息");
		return "eshop/saleEshop";
	}

	/**
	 * h5后台跳转到完善卖店详细信息页面
	 */
	@RequestMapping("addAndModifySaleEshopDetailInfo")
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String addSaleEshopInfo(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		User currentUser = WebUtil.getCurrentUser(request);
		String eshopId = request.getParameter("eshopId");
		Long eshopUserId = HttpUtil.getLongValueFromRequest(request, "eshopUserId");
		int isModifyEshop = 0;
		Eshop eshop = null;
		SaleEshop saleEshop = null;
		EshopCompany eshopCompany = null;
		EshopTrademark eshopTrademark = null;
		if (StringUtils.isNotBlank(eshopId)) {
			eshop = this.eshopService.getEshopByEshopId(Long.parseLong(eshopId));
			if (eshop == null) {
				return null;
			}
			saleEshop = this.saleEshopService.getSaleEshopBySaleEshopId(eshop.getSaleEshopId());
			eshopCompany = this.eshopCompanyService.getEshopCompanyByEshopCompanyId(eshop.getEshopCompanyId());
			eshopTrademark = this.eshopTrademarkService.getEshopTrademarkByEshopTrademarkId(eshop.getTrademarkId());
			isModifyEshop = 1;
		}
		modelMap.put("eshopUserId", eshopUserId);
		modelMap.put("eshop", eshop);
		modelMap.put("saleEshop", saleEshop);
		modelMap.put("eshopCompany", eshopCompany);
		modelMap.put("eshopTrademark", eshopTrademark);
		modelMap.put("isModifyEshop", isModifyEshop);
		modelMap.put("currentUser", currentUser);
		return "eshop/addAndModifySaleEshopDetailInfo";
	}

	/**
	 * h5后台增加或修改出售店鋪的相關信息提交
	 * 
	 * @param turnoverImgFile
	 * @param categoryImgFile
	 * @param secCategoryImgFile
	 * @param koufenImgFile
	 * @param request
	 * @param response
	 * @param modelMap
	 * @param saleEshopQO
	 * @return
	 */
	@RequestMapping(value = "addAndModifySaleEshopDetailInfoAction", method = RequestMethod.POST)
	@EShopUserSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String addSaleEshopInfoAction(@RequestParam("turnoverImgFile") MultipartFile turnoverImgFile,
			@RequestParam("categoryImgFile") MultipartFile categoryImgFile,
			@RequestParam("secCategoryImgFile") MultipartFile secCategoryImgFile,
			@RequestParam("koufenImgFile") MultipartFile koufenImgFile, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap, SaleEshopQO saleEshopQO) {
		// User currentUser = WebUtil.getCurrentUser(request);
		Long eshopId = HttpUtil.getLongValueFromRequest(request, "eshopId");
		Eshop currentEshop = this.eshopService.getEshopByEshopId(eshopId);
		User currentUser = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Long eshopUserId = HttpUtil.getLongValueFromRequest(request, "eshopUserId");
		Integer isModifyEshop = HttpUtil.getIntegerValueFromRequest(request, "isModifyEshop");

		Eshop eshop = saleEshopQO.getEshop();
		SaleEshop saleEshop = saleEshopQO.getSaleEshop();
		EshopCompany eshopCompany = saleEshopQO.getEshopCompany();
		EshopTrademark eshopTrademark = saleEshopQO.getEshopTrademark();

		// 插入公司表
		eshopCompany.setGmtModify(new Date());
		eshopCompany.setCommOnlyKey(onlyKey);
		eshopCompany.setType(0);
		eshopCompany.setStatus(0);
		if (isModifyEshop == 0) {
			eshopCompany.setCreateUserId(currentUser.getId());
			eshopCompany.setGmtCreate(new Date());
			this.eshopCompanyService.insertEshopCompanyByEshopCompany(eshopCompany);

		} else if (isModifyEshop == 1 && currentEshop != null) {
			EshopCompany existEshopCompany = this.eshopCompanyService
					.getEshopCompanyByEshopCompanyId(currentEshop.getEshopCompanyId());
			eshopCompany.setCreateUserId(currentUser.getId());
			this.eshopCompanyService.modifyEshopCompanyByEshopCompany(eshopCompany, existEshopCompany);
		}

		// 插入商标表
		eshopTrademark.setGmtModify(new Date());
		eshopTrademark.setCommOnlyKey(onlyKey);
		eshopTrademark.setStatus(0);
		eshopTrademark.setType(0);
		if (isModifyEshop == 0) {
			eshopTrademark.setGmtCreate(new Date());
			eshopTrademark.setCreateUserId(currentUser.getId());
			this.eshopTrademarkService.insertEshopTrademarkByEshopTrademark(eshopTrademark);
		} else if (isModifyEshop == 1 && currentEshop != null) {
			EshopTrademark existEshopTrademark = this.eshopTrademarkService
					.getEshopTrademarkByEshopTrademarkId(currentEshop.getTrademarkId());
			eshopTrademark.setCreateUserId(currentUser.getId());
			this.eshopTrademarkService.modifyEshopTrademarkByEshopTrademark(eshopTrademark, existEshopTrademark);
		}

		// 插入saleEshop
		// 图片

		if (turnoverImgFile != null && !turnoverImgFile.getOriginalFilename().equals("")) {
			String turnoverImg = imageUploadBizImpl.uploadImage(turnoverImgFile, folder, request);
			if (StringUtils.isNotBlank(turnoverImg)) {
				saleEshop.setTurnoverImg(turnoverImg);
			}
		}

		if (categoryImgFile != null && !categoryImgFile.getOriginalFilename().equals("")) {
			String categoryImg = imageUploadBizImpl.uploadImage(categoryImgFile, folder, request);
			if (StringUtils.isNotBlank(categoryImg)) {
				saleEshop.setCategoryImg(categoryImg);
			}
		}

		if (secCategoryImgFile != null && !secCategoryImgFile.getOriginalFilename().equals("")) {
			String secCategoryImg = imageUploadBizImpl.uploadImage(secCategoryImgFile, folder, request);
			if (StringUtils.isNotBlank(secCategoryImg)) {
				saleEshop.setSecCategoryImg(secCategoryImg);
			}
		}

		if (koufenImgFile != null && !koufenImgFile.getOriginalFilename().equals("")) {
			String koufenImg = imageUploadBizImpl.uploadImage(koufenImgFile, folder, request);
			if (StringUtils.isNotBlank(koufenImg)) {
				saleEshop.setKoufenImg(koufenImg);
			}
		}

		String pyName = PinYinUtil.getPinYinFromChinese(saleEshop.getProvinceName()) + saleEshop.getProvinceName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getCityName()) + saleEshop.getCityName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getAreaName()) + saleEshop.getAreaName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getChinaArea()) + saleEshop.getChinaArea()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getEshopFeature()) + saleEshop.getEshopFeature()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getSellerMessage()) + saleEshop.getSellerMessage()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getMainGoods()) + saleEshop.getMainGoods()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getCategoryName()) + saleEshop.getCategoryName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getTitle()) + saleEshop.getTitle()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getSecCategoryName()) + saleEshop.getSecCategoryName();
		saleEshop.setPyName(pyName);
		saleEshop.setTaxpayerType(eshopCompany.getTaxpayerQualification());
		saleEshop.setTrademarkType(eshopTrademark.getTrademarkType());
		saleEshop.setGmtModify(new Date());
		saleEshop.setShowPrice(saleEshop.getShowPrice());
		saleEshop.setPrice(MoneyUtil.getEshopPrice(saleEshop.getShowPrice()));
		saleEshop.setTrademarkType(eshopTrademark.getTrademarkType());
		saleEshop.setTaxpayerType(eshopCompany.getTaxpayerQualification());
		saleEshop.setCommOnlyKey(onlyKey);
		saleEshop.setType(0);
		saleEshop.setStatus(0);
		String eshopSearchDir = propertiesConfigure.getProperties(PropertiesKey.eshopsearchdir);
		if (isModifyEshop == 0) {
			saleEshop.setEshopCompanyId(eshopCompany.getId());
			saleEshop.setTrademarkId(eshopTrademark.getId());
			saleEshop.setEshopNo(this.saleEshopService.generateEshopNo());
			saleEshop.setPyName(pyName + saleEshop.getEshopNo());
			saleEshop.setGmtCreate(new Date());
			this.saleEshopService.insertSaleEshopBySaleEshop(saleEshop);
			eshopCompany.setSaleEshopId(saleEshop.getId());
			this.eshopCompanyService.modifyEshopCompanyByKey(eshopCompany);
			eshopTrademark.setSaleEshopId(saleEshop.getId());
			this.eshopTrademarkService.modifyEshopTrademarkByKey(eshopTrademark);
			List<SaleEshop> saleEshopList = new ArrayList<>();
			saleEshopList.add(saleEshop);
			this.eShopLuceneBuildService.buildAll(saleEshopList, eshopSearchDir);
		} else if (isModifyEshop == 1 && currentEshop != null) {
			SaleEshop existSaleEshop = this.saleEshopService.getSaleEshopBySaleEshopId(currentEshop.getSaleEshopId());
			this.saleEshopService.modifySaleEshopBySaleEshop(saleEshop, existSaleEshop);
			List<SaleEshop> saleEshopList = new ArrayList<>();
			saleEshopList.add(saleEshop);
			this.eShopLuceneBuildService.update(saleEshopList, eshopSearchDir);
		}

		// 插入eshop表
		eshop.setGmtModify(new Date());
		eshop.setCommOnlyKey(onlyKey);
		if (isModifyEshop == 0) {
			eshop.setGmtCreate(new Date());
			eshop.setEshopCompanyId(eshopCompany.getId());
			eshop.setSaleEshopId(saleEshop.getId());
			eshop.setTrademarkId(eshopTrademark.getId());
			eshop.setCreateUserId(currentUser.getId());
			eshop.setEshopSellerId(eshopUserId);
			this.eshopService.insertEshopByEshop(eshop);
			EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(eshopUserId);
			eshopUserInfo.setEshopId(eshop.getId());
			eshopUserInfo.setUserId(currentUser.getId());
			this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo);
		}
		if (isModifyEshop == 1 && currentEshop != null) {
			eshop.setCreateUserId(currentUser.getId());
			Eshop existEshop = this.eshopService.getEshopByEshopId(currentEshop.getId());
			this.eshopService.modifyEshopByEshop(eshop, existEshop);
		}
		return "redirect:/eshop/backeshopinfoList.htm?type=0";
	}

	/**
	 * h5店铺详情页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("saleEshopDetail")
	public String SaleEshopDetail(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		eshopDetail(request, response, modelMap);
		return "eshop/saleEshopDetail";
	}

	/**
	 * 店铺详情页的modelMap
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	public ModelMap eshopDetail(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Long saleEshopId = HttpUtil.getLongValueFromRequest(request, "saleEshopId");
		SaleEshopVO saleEshopVO = this.eshopBizImpl.getSaleEshopBySaleEshopId(saleEshopId);

		// 如果用户登录，判断该店铺是否已经被收藏
		User user = WebUtil.getCurrentUser(request);
		Integer collectionStatus = this.collectionBizImpl.isCollection(onlyKey, saleEshopId, user,
				CollectionEnum.ESHOPTYPE.getCode());

		modelMap.put("user", user);
		modelMap.put("collectionStatus", collectionStatus);
		modelMap.put("saleEshopVO", saleEshopVO);
		return modelMap;
	}

	/**
	 * h5个人中心
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("personalCenter")
	@EShopUserSecurity
	public String personalCenter(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		User user = WebUtil.getCurrentUser(request);
		if (user.getType() == UserConstant.TYPE_MANAGE) {
			return "eshop/backoperate";
		}
		personalCenterModelMap(request, response, modelMap);
		return "eshop/personalCenter";
	}

	/**
	 * pc端个人中心
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcPersonalCenter")
	@EShopUserSecurity(isPc = true)
	public String pcPersonalCenter(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		User user = WebUtil.getCurrentUser(request);
		if (user.getType().intValue() == 5) {
			return "redirect:/eshop/backEshop/backManage.htm";
		}
		personalCenterModelMap(request, response, modelMap);
		return "eshop/pcPersonalCenter";
	}

	/**
	 * pc端个人中心收藏列表分页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcCollectionInclude")
	@EShopUserSecurity(isPc = true)
	public String pcCollectionInclude(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		personalCenterModelMap(request, response, modelMap);
		return "eshop/pcCollectionInclude";
	}

	// 个人中心modelMap
	public ModelMap personalCenterModelMap(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		User user = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		// 设置分页
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize",
				PageUtil.PAGE_SIZE_ESHOPCOLLECTION);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		List<Collection> collectionList = this.collectionBizImpl.getCollectionByUserIdAndOnlyKey(user.getId(), onlyKey,
				null, page, CollectionEnum.ESHOPTYPE.getCode(), 0);
		List<SaleEshop> saleEshopList = new ArrayList<SaleEshop>();
		if (collectionList != null && collectionList.size() > 0) {
			for (Collection collection : collectionList) {
				saleEshopList.add(this.saleEshopService.getSaleEshopBySaleEshopId(collection.getMallId()));
			}
		}
		int size = this.collectionBizImpl.getCollectionByUserIdAndOnlyKey(user.getId(), onlyKey, null, null,
				CollectionEnum.ESHOPTYPE.getCode(), 0).size();

		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE_ESHOPCOLLECTION);
		modelMap.put("pageCount", pageCount);
		UserExtended userExtended = this.userExtendedService.getUserExtendByUserId(user.getId());
		modelMap.put("userExtended", userExtended);
		modelMap.put("saleEshopList", saleEshopList);
		modelMap.put("user", user);
		modelMap.put("pageNo", pageNo);
		return modelMap;
	}

	/**
	 * pc收藏店铺
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 */
	@RequestMapping("pcAddOrCancelCollection")
	@EShopUserSecurity(isPc = true)
	public ResponseEntity<Collection> pcAddOrCancelCollection(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		return doCollection(request, response, modelMap);
	}

	/**
	 * h5收藏店铺
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 */
	@RequestMapping("addOrCancelCollection")
	@EShopUserSecurity
	public ResponseEntity<Collection> addOrCancelCollection(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		return doCollection(request, response, modelMap);
	}

	/**
	 * 收藏店铺具体操作
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	public ResponseEntity<Collection> doCollection(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Collection> responseEntity = new ResponseEntity<>();
		User user = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Long saleEshopId = HttpUtil.getLongValueFromRequest(request, "saleEshopId");
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");

		if (saleEshopId == null || saleEshopId <= 0) {
			responseEntity.setCode("-400");
			responseEntity.setData(null);
			responseEntity.setMessage("店铺不存在");
			return responseEntity;
		}
		int num = this.collectionBizImpl.addOrCancelCollection(user.getId(), onlyKey, saleEshopId,
				CollectionEnum.ESHOPTYPE.getCode(), status);

		if (num == 0) {
			responseEntity.setCode("-200");
			responseEntity.setData(null);
			responseEntity.setMessage("操作失败");
			return responseEntity;
		}
		responseEntity.setCode("200");
		responseEntity.setData(null);
		responseEntity.setMessage("操作成功");
		return responseEntity;
	}

	/**
	 * 快速提交留言
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("pcquicksubmitAction")
	@ResponseBody
	public ResponseEntity<EshopUserInfo> pcQuickSubmit(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<EshopUserInfo> responseEntity = new ResponseEntity<>();
		EshopUserInfo eshopUserInfo = new EshopUserInfo();
		String remark = request.getParameter("remark");
		String phone = request.getParameter("phone");
		String name = request.getParameter("phone");
		User user = WebUtil.getCurrentUser(request);
		eshopUserInfo.setName(name);
		eshopUserInfo.setPhone(phone);
		eshopUserInfo.setType(7);
		eshopUserInfo.setRemark(remark);
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		eshopUserInfo.setStatus(0);
		if (user != null) {
			eshopUserInfo.setUserId(user.getId());
		}
		eshopUserInfo.setCommOnlyKey(HttpUtil.getCommkeyId(request, response));
		this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		responseEntity.initSuccResponseEntity(eshopUserInfo, "succ");
		if (!responseEntity.getCode().equals("200")) {
			Log4jUtil.printLog(EshopErrorTypeEnum.SELLERERROR.getDesc(), eshopUserInfo.getPhone());
		}
		this.verifyCodeBizImpl.sendMessToMaigedianManager(MaiGeDianWebUtil.managerPhone,
				"用户：" + name + "  手机：" + phone + "提交了快速需求");
		return responseEntity;
	}

	@RequestMapping("pcquicksubmit")
	public String pcquicksubmit(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		this.eshopBizImpl.putUserIntoMap(request, response, modelMap);
		return "eshop/pcquicksubmit";
	}

	/**
	 * 运营主动联系天猫店铺
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("eshopTouchList")
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String eshopTouchList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		eshopTouchListModelMap(request, response, modelMap);
		return "eshop/eshopTouchList";
	}

	@RequestMapping("eshopTouchListMore")
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String eshopTouchListMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		eshopTouchListModelMap(request, response, modelMap);
		return "eshop/eshopTouchListMore";
	}

	public ModelMap eshopTouchListModelMap(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		String keyWord = HttpUtil.getStringValueFromRequest(request, "keyWord");
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		EshopTouchExample example = new EshopTouchExample();
		example.setOrderByClause("id desc");
		com.mall.pojo.EshopTouchExample.Criteria criteria = example.createCriteria();
		if (StringUtils.isNotBlank(keyWord)) {
			criteria.andPyNameLike("%" + keyWord + "%");
		}
		criteria.andCommOnlyKeyEqualTo(onlyKey);
		if (status != null) {
			criteria.andStatusEqualTo(status);
		}
		List<EshopTouch> eshopTouchList = this.eshopTouchService.getEshopTouchListByExample(example);
		modelMap.put("eshopTouchList", eshopTouchList);
		return modelMap;
	}

	@RequestMapping("addEshopTouchAction")
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	@ResponseBody
	public ResponseEntity<String> addEshopTouchAction(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		User user = WebUtil.getCurrentUser(request);
		String eshopName = HttpUtil.getStringValueFromRequest(request, "eshopName");
		EshopTouch eshopTouch = new EshopTouch();
		if (StringUtils.isBlank(eshopName)) {
			responseEntity.initErrorResponseEntity("-300", "没有填写店铺名");
			return responseEntity;
		}
		eshopTouch.setEshopName(eshopName);
		eshopTouch.setCreateUserId(user.getId());
		eshopTouch.setCommOnlyKey(onlyKey);
		eshopTouch.setEshopType(0);
		eshopTouch.setStatus(0);
		eshopTouch.setGmtCreate(new Date());
		eshopTouch.setGmtModify(new Date());
		String pyName = PinYinUtil.getPinYinFromChinese(eshopName) + eshopName;
		eshopTouch.setPyName(pyName);
		int isInsert = this.eshopTouchService.insertEshopTouch(eshopTouch);
		if (isInsert <= 0) {
			responseEntity.initErrorResponseEntity("-200", "操作失败");
			return responseEntity;
		}
		responseEntity.initSuccResponseEntity("200", "操作成功");
		return responseEntity;
	}

	/**
	 * 修改店铺联系信息
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("modifyEshopTouchStatus")
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	@ResponseBody
	public ResponseEntity<String> modifyEshopTouchStatus(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		String remark = HttpUtil.getStringValueFromRequest(request, "remark");
		Long eshopTouchId = HttpUtil.getLongValueFromRequest(request, "eshopTouchId");
		EshopTouch eshopTouch = this.eshopTouchService.getEshopTouchById(eshopTouchId);
		if (status != null) {
			eshopTouch.setStatus(status);
		}
		if (StringUtils.isNotBlank(remark)) {
			eshopTouch.setRemark(remark);
		}
		eshopTouch.setGmtModify(new Date());
		int isModify = this.eshopTouchService.modifyEshopTouch(eshopTouch);
		if (isModify <= 0) {
			responseEntity.initErrorResponseEntity("-200", "操作失败");
			return responseEntity;
		}
		responseEntity.initSuccResponseEntity("200", "操作成功");
		return responseEntity;
	}

	// bananer图公司简介
	@RequestMapping("pcEshopSummary")
	public String pcEshopSummary(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "eshop/pcEshopSummary";
	}

	// 根据网友发的id查看店铺基本信息
	@RequestMapping("getSaleEshopById")
	public String getSaleEshopById(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {

		return "eshop/pcEshopSummary";
	}

}
